// pages/ind_user/ind_user.js
const app = getApp();
const md5 = require('../../utils/md5.js');
const util = require('../../utils/util.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    b1: 'url("https://www.zhibohome.net/images/industry/ind_clicked.png")',
    b2: null,
    b3: null,

    t1: '#fff',
    t2: null,
    t3: null,

    ind_flag: "day",

    day: null,
    month: null,

    tuhao_all: [], //土豪用户

    idx: 1,

    day_start_date: '',
    day_end_date: '',

    month_start_date: '',
    month_end_date: '',

    week_start_date: '',
    week_end_date: '',

    date_month: null, //判断月份
    showWeek: '',


    week_date: [],


    ind_module: '', //模块

    plat_head: '', //头部
    platfrom_name: '',

    collect_type: '', //头部选择身份模块

    current_Tab: null, //当前cur

    head_switch: true, //选择全部

    head_id: null, //头部选择平台ID
    head_type: null, //头部选择平台类型

    module_: null,

    selAddress: false, //返回成功


  },
  more_plat: function() {
    wx.navigateTo({
      url: '../ind_plat/ind_plat',
    })
  },
  click_day: function() {
    var url = 'url("https://www.zhibohome.net/images/industry/ind_clicked.png")';
    // console.log(1)

    this.setData({
      b1: url,
      b2: null,
      b3: null,

      t1: '#fff',
      t2: null,
      t3: null,

      ind_flag: "day",
      tuhao_all: [],

      // showWeek: '',
      // month: '',
      // day: '',
      idx: 1,
    })
    // 发起请求
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
    //调用 函数
    if (!(this.data.head_id)) {
      switch (this.data.module_) {
        case "user":
          this.tuhao_data(plat_token, this.data.day_start_date, this.data.day_start_date, "day");
          break;
        case "gift":
          this.gift_data(plat_token, this.data.day_start_date, this.data.day_start_date, "day");
          break;
        case "mes":
          this.mes_data(plat_token, this.data.day_start_date, this.data.day_start_date, "day");
          break;
      }
    } else {
      this.plat_data(plat_token, this.data.head_id, this.data.day_start_date, this.data.day_end_date, this.data.head_type, 'day')
    }
    //显示日期
    this.show_day(app.globalData.now_time)
  },
  click_week: function() {
    var url = 'url("https://www.zhibohome.net/images/industry/ind_clicked.png")';
    // console.log(2)

    this.setData({
      b1: null,
      b2: url,
      b3: null,

      t1: null,
      t2: '#fff',
      t3: null,

      ind_flag: "week",
      tuhao_all: [],

      showWeek: '',
      month: '',
      day: '',
      idx: 1,

    })
    var date = new Date();
    var nowTime = Date.parse(date.getFullYear() + '/' + ((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1)) + '/' + (date.getDate() > 9 ? (date.getDate()) : '0' + (date.getDate()))) / 1000
    var day = date.getDay();
    var oneDayTime = 24 * 60 * 60;

    var MondayTime = nowTime - (day - 1) * oneDayTime;
    var SundayTime = nowTime + (7 - day) * oneDayTime;
    //设置时间
    console.log('MondayTime+' + MondayTime)
    console.log('SundayTime+' + SundayTime)
    this.setData({
      week_start_date: MondayTime,
      week_end_date: SundayTime,
    })
    console.log(util.formatTimeFive(MondayTime, "M月D日"));
    var date_m = (util.formatTimeFive(MondayTime, "M月D日")) + '-' + (util.formatTimeFive(SundayTime, "M月D日"))
    this.setData({
      showWeek: date_m
    })


    //请求数据
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
    //调用 函数
    if (!(this.data.head_id)) {
      switch (this.data.module_) {
        case "user":
          this.tuhao_data(plat_token, this.data.week_start_date, this.data.week_end_date, "whole_week");
          break;
        case "gift":
          this.gift_data(plat_token, this.data.week_start_date, this.data.week_end_date, "whole_week");
          break;
        case "mes":
          this.mes_data(plat_token, this.data.week_start_date, this.data.week_end_date, "whole_week");
          break;
      }
    } else {
      this.plat_data(plat_token, this.data.head_id, this.data.week_start_date, this.data.week_end_date, this.data.head_type, 'whole_week')
    }
    //显示日期
    this.show_month(app.globalData.now_month) //=======================================

  },
  click_month: function() {
    var url = 'url("https://www.zhibohome.net/images/industry/ind_clicked.png")';
    // console.log(3)

    this.setData({
      b1: null,
      b2: null,
      b3: url,

      t1: null,
      t2: null,
      t3: '#fff',

      ind_flag: "month",
      tuhao_all: [],

      show_day: null,
      show_week: null,
      show_month: null,

      showWeek: '',
      month: '',
      day: '',
      idx: 1,
    })
    var date = new Date();
    var month = ((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1)).toString()
    var date_month = date.getFullYear() + '-' + ((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1))
    var start_month = Date.parse(date.getFullYear() + '-' + ((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1)) + '-01') / 1000 - 28800
    this.setData({
      date_month: date_month
    })
    this.cul_month(month);
    //设置:月初/月末
    this.setData({
      month_start_date: start_month
    })




    //请求数据
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
    //调用 函数
    if (!(this.data.head_id)) {
      switch (this.data.module_) {
        case "user":
          this.tuhao_data(plat_token, this.data.month_start_date, this.data.month_end_date, "whole_month");
          break;
        case "gift":
          this.gift_data(plat_token, this.data.month_start_date, this.data.month_end_date, "whole_month");
          break;
        case "mes":
          this.mes_data(plat_token, this.data.month_start_date, this.data.month_end_date, "whole_month");
          break;
      }
    } else {
      this.plat_data(plat_token, this.data.head_id, this.data.month_start_date, this.data.month_end_date, this.data.head_type, 'whole_month')
    }
    //显示日期
    this.show_month(app.globalData.now_month)
  },

  //滚轮日
  bindDateChange_day: function(e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date_day: e.detail.value,
      ind_flag: "day",
      idx: 1,
      tuhao_all: []
    })
    var day_time = e.detail.value
    this.show_day(e.detail.value) //转换 页面显示时间


    var day_start_date = Date.parse(day_time) / 1000 - 28800;
    this.setData({
      day_start_date: day_start_date,
      day_end_date: day_start_date
    })
    // console.log('11111+' + this.data.day_start_date)
    //请求数据
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
    //调用 函数
    if (!(this.data.head_id)) {
      switch (this.data.module_) {
        case "user":
          this.tuhao_data(plat_token, this.data.day_start_date, this.data.day_start_date, "day");
          break;
        case "gift":
          this.gift_data(plat_token, this.data.day_start_date, this.data.day_start_date, "day");
          break;
        case "mes":
          this.mes_data(plat_token, this.data.day_start_date, this.data.day_start_date, "day");
          break;
      }
    } else {
      this.plat_data(plat_token, this.data.head_id, this.data.day_start_date, this.data.day_end_date, this.data.head_type, 'day')
    }



  },


  //滚轮周
  bindDateChange_week: function(e) {
    // console.log('zhou+' + this.data.week_date[e.detail.value])

    var cul_week = this.data.week_date[e.detail.value]
    var showWeek = cul_week.slice(5, 7) + '月' + cul_week.slice(8, 10) + '日-' + cul_week.slice(11, 13) + '月' + cul_week.slice(14, 16) + '日'
    // console.log(showWeek)


    var year = (app.globalData.now_time).slice(0, 4)
    // console.log(cul_week)

    var pj_week_start = year + '/' + (this.data.week_date[e.detail.value]).substring(5, 10)
    var pj_week_end = year + '/' + (this.data.week_date[e.detail.value]).substring(11, 16)

    var date1 = new Date(pj_week_start)
    var sjc1 = date1.getTime() / 1000
    var date2 = new Date(pj_week_end)
    var sjc2 = date2.getTime() / 1000
    this.setData({
      week_start_date: sjc1,
      week_end_date: sjc2,
      tuhao_all: [],
      showWeek: showWeek
    })
    console.log(this.data.week_start_date)
    console.log(this.data.week_end_date)

    //请求数据
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
    //调用 函数
    if (!(this.data.head_id)) {
      switch (this.data.module_) {
        case "user":
          this.tuhao_data(plat_token, this.data.week_start_date, this.data.week_end_date, "whole_week");
          break;
        case "gift":
          this.gift_data(plat_token, this.data.week_start_date, this.data.week_end_date, "whole_week");
          break;
        case "mes":
          this.mes_data(plat_token, this.data.week_start_date, this.data.week_end_date, "whole_week");
          break;
      }
    } else {
      this.plat_data(plat_token, this.data.head_id, this.data.week_start_date, this.data.week_end_date, this.data.head_type, 'whole_week')
    }

  },


  //滚轮月
  bindDateChange_month: function(e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    // var date_month = e.detail.value
    this.setData({
      date_month: e.detail.value,
      ind_flag: "month",
      idx: 1,
      tuhao_all: []
    })
    this.show_month(e.detail.value)
    //开始时间
    var month = e.detail.value.slice(5, 7)
    var month_start_date = Date.parse((e.detail.value) + '-01') / 1000 - 28800;

    this.setData({
      month_start_date: month_start_date
    })
    //结束时间
    this.cul_month(month)
    // console.log('month+' + month)

    //请求数据
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
    //调用 函数
    if (!(this.data.head_id)) {
      switch (this.data.module_) {
        case "user":
          this.tuhao_data(plat_token, this.data.month_end_date, this.data.month_end_date, "whole_month");
          break;
        case "gift":
          this.gift_data(plat_token, this.data.month_end_date, this.data.month_end_date, "whole_month");
          break;
        case "mes":
          this.mes_data(plat_token, this.data.month_end_date, this.data.month_end_date, "whole_month");
          break;
      }
    } else {
      this.plat_data(plat_token, this.data.head_id, this.data.month_start_date, this.data.month_end_date, this.data.head_type, 'whole_month')
    }



  },
  //页面显示天
  show_day: function(time) {
    var time = time.toString();
    var year = time.slice(0, 4);
    var month = time.slice(5, 7);
    var day = time.slice(8, 11);

    this.setData({
      day: year + '年' + month + '月' + day + '日'
    })
    // console.log(year + '年' + month + '月' + day + '日')

  },
  //页面显示月
  show_month: function(time) {
    var time = time.toString();
    var year = time.slice(0, 4);
    var month = time.slice(5, 7);

    this.setData({
      month: year + '年' + month + '月'
    })
    // console.log(year + '年' + month + '月')

  },
  //土豪
  tuhao_data: function(token, start, end, time) {
    wx.showLoading({
      title: '小主稍等~',
    })
    var that = this;
    // console.log(time)
    wx.request({
      method: 'POST',
      url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/top',
      data: {
        token: token,
        strattime: start,
        endtime: end,
        timeSlot: time
      },
      success: function(e) {
        var tuhao = e.data.data.tuhao.data;
        var tuhao_last = that.data.tuhao_all.push(...tuhao)
        that.setData({
          tuhao_all: that.data.tuhao_all
        })
        // console.log(that.data.tuhao_all)
      }
    })

    wx.hideLoading();
  },
  //礼物
  gift_data: function(token, start, end, time) {
    wx.showLoading({
      title: '小主稍等~',
    })
    var that = this;
    // console.log(time)
    wx.request({
      method: 'POST',
      url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/top',
      data: {
        token: token,
        strattime: start,
        endtime: end,
        timeSlot: time
      },
      success: function(e) {
        // console.log(e.data.data.total)
        var tuhao = e.data.data.total;
        var tuhao_last = that.data.tuhao_all.push(...tuhao)
        that.setData({
          tuhao_all: that.data.tuhao_all
        })
        // console.log(that.data.tuhao_all)
      }
    })

    wx.hideLoading();
  },
  mes_data: function(token, start, end, time) {
    wx.showLoading({
      title: '小主稍等~',
    })
    var that = this;
    // console.log(time)
    wx.request({
      method: 'POST',
      url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/top',
      data: {
        token: token,
        strattime: start,
        endtime: end,
        timeSlot: time
      },
      success: function(e) {
        // console.log(e.data.data.total)
        var tuhao = e.data.data.total;
        var tuhao_last = that.data.tuhao_all.push(...tuhao)
        that.setData({
          tuhao_all: that.data.tuhao_all
        })
        // console.log(that.data.tuhao_all)
      }
    })

    wx.hideLoading();
  },
  //平台
  plat_data: function(token, pid, start, end, type, time, page) {
    // console.log('module+'+this.data.module_)
    // console.log(this.data.head_id)
    wx.showLoading({
      title: '小主稍等~',
    })
    var that = this;
    var module_ = this.data.module_
    wx.request({
      method: 'POST',
      url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/topsingle',
      data: {
        token: token,
        pid: pid,
        strattime: start,
        endtime: end,
        timeSlot: time,
        page: page,
        type: type
      },
      success: function(e) {
        //不同模块
        switch (that.data.module_) {
          case "user":
            var tuhao = e.data.data.tuhao.data;
            break;
          case "gift":
            // console.log(e)
            var tuhao = e.data.data.gifts.data;
            break;
          case "mes":
            var tuhao = e.data.data.bullet.data;
            break;
        }
        // console.log(e)
        // var tuhao = e.data.data.tuhao.data;
        var tuhao_last = that.data.tuhao_all.push(...tuhao)
        that.setData({
          tuhao_all: that.data.tuhao_all
        })
        // console.log(that.data.tuhao_all)
      }
    })

    wx.hideLoading();
    console.log('token:' + token + '+pid:' + pid + '+strat:' + start + '+end:' + end + '+type:' + type + '+time:' + time + '+page:' + page)
  },

  //点击更多
  click_more: function() {
    wx.showLoading({
      title: '小主稍等~',
    })
    this.setData({
      idx: this.data.idx + 1,
    })


    if (this.data.ind_flag == "day") {
      // console.log('走day')
      //token
      var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
      //调用 函数
      var that = this;
      // console.log('2222+' + this.data.day_start_date)
      if (!(this.data.head_id)) {
        wx.request({
          method: 'POST',
          url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/top',
          data: {
            token: plat_token,
            strattime: this.data.day_start_date,
            endtime: this.data.day_start_date,
            timeSlot: "day",
            page: that.data.idx
          },
          success: function(e) {
            // console.log(e)
            // console.log(e.data.data.tuhao.data)
            var tuhao = e.data.data.tuhao.data;
            var new_tuhao = that.data.tuhao_all.push(...tuhao)
            that.setData({
              tuhao_all: that.data.tuhao_all
            })
          }
        })
      } else {
        if (that.data.head_type) {
          if (that.data.module_ == "gift") {
            wx.request({
              method: 'POST',
              url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/topsingle',
              data: {
                token: plat_token,
                pid: that.data.head_id,
                strattime: this.data.day_start_date,
                endtime: this.data.day_start_date,
                timeSlot: "day",
                type: that.data.head_type,
                page: that.data.idx
              },
              success: function(e) {
                console.log(e.data.data.gifts.data)
                // console.log('走这里+' + that.data.head_id)
                // console.log(e.data.data.tuhao.data)
                var tuhao = e.data.data.gifts.data;
                var new_tuhao = that.data.tuhao_all.push(...tuhao)
                that.setData({
                  tuhao_all: that.data.tuhao_all
                })
              }
            })
          } else if (that.data.module_ == "mes") {
            wx.request({
              method: 'POST',
              url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/topsingle',
              data: {
                token: plat_token,
                pid: that.data.head_id,
                strattime: this.data.day_start_date,
                endtime: this.data.day_start_date,
                timeSlot: "day",
                type: that.data.head_type,
                page: that.data.idx
              },
              success: function(e) {
                console.log(e.data.data.bullet.data)
                // console.log('走这里+' + that.data.head_id)
                // console.log(e.data.data.tuhao.data)
                var tuhao = e.data.data.bullet.data;
                var new_tuhao = that.data.tuhao_all.push(...tuhao)
                that.setData({
                  tuhao_all: that.data.tuhao_all
                })
              }
            })
          }

        } else {
          wx.request({
            method: 'POST',
            url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/topsingle',
            data: {
              token: plat_token,
              pid: that.data.head_id,
              strattime: this.data.day_start_date,
              endtime: this.data.day_start_date,
              timeSlot: "day",
              type: that.data.head_type,
              page: that.data.idx
            },
            success: function(e) {
              // console.log(e)
              // console.log('走这里+' + that.data.head_id)
              // console.log(e.data.data.tuhao.data)
              var tuhao = e.data.data.tuhao.data;
              var new_tuhao = that.data.tuhao_all.push(...tuhao)
              that.setData({
                tuhao_all: that.data.tuhao_all
              })
            }
          })
        }

      }

    } else {};
    if (this.data.ind_flag == "week") {
      // console.log('走week')
      //token
      var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
      //调用 函数
      var that = this;
      if (!(this.data.head_id)) {
        wx.request({
          method: 'POST',
          url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/top',
          data: {
            token: plat_token,
            strattime: this.data.week_start_date,
            endtime: this.data.week_end_date,
            timeSlot: 'whole_week',
            page: that.data.idx
          },
          success: function(e) {
            // console.log(e)
            // console.log(e.data.data.tuhao.data)
            var tuhao = e.data.data.tuhao.data;
            var new_tuhao = that.data.tuhao_all.push(...tuhao)
            that.setData({
              tuhao_all: that.data.tuhao_all
            })
          }
        })
      } else {
        if (that.data.head_type) {
          if (that.data.module_ == "gift") {
            wx.request({
              method: 'POST',
              url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/topsingle',
              data: {
                token: plat_token,
                pid: that.data.head_id,
                strattime: this.data.week_start_date,
                endtime: this.data.week_end_date,
                timeSlot: "whole_week",
                type: that.data.head_type,
                page: that.data.idx
              },
              success: function(e) {
                console.log(e.data.data.gifts.data)
                // console.log('走这里+' + that.data.head_id)
                // console.log(e.data.data.tuhao.data)
                var tuhao = e.data.data.gifts.data;
                var new_tuhao = that.data.tuhao_all.push(...tuhao)
                that.setData({
                  tuhao_all: that.data.tuhao_all
                })
              }
            })
          } else if (that.data.module_ == "mes") {
            wx.request({
              method: 'POST',
              url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/topsingle',
              data: {
                token: plat_token,
                pid: that.data.head_id,
                strattime: this.data.week_start_date,
                endtime: this.data.week_end_date,
                timeSlot: "whole_week",
                type: that.data.head_type,
                page: that.data.idx
              },
              success: function(e) {
                console.log(e.data.data.bullet.data)
                // console.log('走这里+' + that.data.head_id)
                // console.log(e.data.data.tuhao.data)
                var tuhao = e.data.data.bullet.data;
                var new_tuhao = that.data.tuhao_all.push(...tuhao)
                that.setData({
                  tuhao_all: that.data.tuhao_all
                })
              }
            })
          }

        } else {
          wx.request({
            method: 'POST',
            url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/topsingle',
            data: {
              token: plat_token,
              pid: that.data.head_id,
              strattime: this.data.week_start_date,
              endtime: this.data.week_end_date,
              timeSlot: "whole_week",
              type: that.data.head_type,
              page: that.data.idx
            },
            success: function(e) {
              // console.log(e)
              // console.log('走这里+' + that.data.head_id)
              // console.log(e.data.data.tuhao.data)
              var tuhao = e.data.data.tuhao.data;
              var new_tuhao = that.data.tuhao_all.push(...tuhao)
              that.setData({
                tuhao_all: that.data.tuhao_all
              })
            }
          })
        }




        // wx.request({
        //   method: 'POST',
        //   url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/topsingle',
        //   data: {
        //     token: plat_token,
        //     pid: that.data.head_id,
        //     type: that.data.head_type,
        //     strattime: this.data.day_start_date,
        //     endtime: this.data.week_end_date,
        //     timeSlot: "whole_week",
        //     page: that.data.idx
        //   },
        //   success: function(e) {
        //     console.log(e)
        //     // console.log(e.data.data.tuhao.data)
        //     var tuhao = e.data.data.tuhao.data;
        //     var new_tuhao = that.data.tuhao_all.push(...tuhao)
        //     that.setData({
        //       tuhao_all: that.data.tuhao_all
        //     })
        //   }
        // })
      }


    } else {};
    if (this.data.ind_flag == "month") {
      // console.log('走month')
      //token
      var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
      //调用 函数
      var that = this;
      if (!(this.data.head_id)) {
        wx.request({
          method: 'POST',
          url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/top',
          data: {
            token: plat_token,
            strattime: this.data.month_start_date,
            endtime: this.data.month_end_date,
            timeSlot: 'whole_month',
            page: that.data.idx
          },
          success: function(e) {
            console.log(e)
            // console.log(e.data.data.tuhao.data)
            var tuhao = e.data.data.tuhao.data;
            var new_tuhao = that.data.tuhao_all.push(...tuhao)
            that.setData({
              tuhao_all: that.data.tuhao_all
            })
          }
        })
      } else {
        if (that.data.head_type) {
          if (that.data.module_ == "gift") {
            wx.request({
              method: 'POST',
              url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/topsingle',
              data: {
                token: plat_token,
                pid: that.data.head_id,
                strattime: this.data.month_start_date,
                endtime: this.data.month_end_date,
                timeSlot: "whole_month",
                type: that.data.head_type,
                page: that.data.idx
              },
              success: function(e) {
                console.log(e.data.data.gifts.data)
                // console.log('走这里+' + that.data.head_id)
                // console.log(e.data.data.tuhao.data)
                var tuhao = e.data.data.gifts.data;
                var new_tuhao = that.data.tuhao_all.push(...tuhao)
                that.setData({
                  tuhao_all: that.data.tuhao_all
                })
              }
            })
          } else if (that.data.module_ == "mes") {
            wx.request({
              method: 'POST',
              url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/topsingle',
              data: {
                token: plat_token,
                pid: that.data.head_id,
                strattime: this.data.month_start_date,
                endtime: this.data.month_end_date,
                timeSlot: "whole_month",
                type: that.data.head_type,
                page: that.data.idx
              },
              success: function(e) {
                console.log(e.data.data.bullet.data)
                // console.log('走这里+' + that.data.head_id)
                // console.log(e.data.data.tuhao.data)
                var tuhao = e.data.data.bullet.data;
                var new_tuhao = that.data.tuhao_all.push(...tuhao)
                that.setData({
                  tuhao_all: that.data.tuhao_all
                })
              }
            })
          }

        } else {
          wx.request({
            method: 'POST',
            url: 'https://xcz.zhibohome.net/api/home/' + this.data.ind_module + '/topsingle',
            data: {
              token: plat_token,
              pid: that.data.head_id,
              strattime: this.data.month_start_date,
              endtime: this.data.month_end_date,
              timeSlot: "whole_month",
              type: that.data.head_type,
              page: that.data.idx
            },
            success: function(e) {
              var tuhao = e.data.data.tuhao.data;
              var new_tuhao = that.data.tuhao_all.push(...tuhao)
              that.setData({
                tuhao_all: that.data.tuhao_all
              })
            }
          })
        }

      }

    } else {};

    wx.hideLoading();
  },
  cul_month: function(month) {
    var year = (app.globalData.now_time).slice(0, 4)
    //开始判断
    switch (month) {
      case "01":

        console.log("大月")
        //月 最后一天
        var month_end_date = Date.parse((this.data.date_month) + '-31') / 1000 - 28800
        this.setData({
          month_end_date: month_end_date
        })
        break;

      case "03":



        console.log("大月")
        //月 最后一天
        var month_end_date = Date.parse((this.data.date_month) + '-31') / 1000 - 28800
        this.setData({
          month_end_date: month_end_date
        })
        break;

      case "05":


        console.log("大月")
        //月 最后一天
        var month_end_date = Date.parse((this.data.date_month) + '-31') / 1000 - 28800
        this.setData({
          month_end_date: month_end_date
        })
        break;

      case "07":


        console.log("大月")
        //月 最后一天
        var month_end_date = Date.parse((this.data.date_month) + '-31') / 1000 - 28800
        this.setData({
          month_end_date: month_end_date
        })
        break;

      case "08":


        console.log("大月")
        //月 最后一天
        var month_end_date = Date.parse((this.data.date_month) + '-31') / 1000 - 28800
        this.setData({
          month_end_date: month_end_date
        })
        break;

      case "10":


        console.log("大月")
        //月 最后一天
        var month_end_date = Date.parse((this.data.date_month) + '-31') / 1000 - 28800
        this.setData({
          month_end_date: month_end_date
        })
        break;

      case "12":


        console.log("大月")
        //月 最后一天
        var month_end_date = Date.parse((this.data.date_month) + '-31') / 1000 - 28800
        this.setData({
          month_end_date: month_end_date
        })
        break;

      case "04":


        console.log("小月")
        //月 最后一天
        var month_end_date = Date.parse((this.data.date_month) + '-30') / 1000 - 28800
        this.setData({
          month_end_date: month_end_date
        })
        break;

      case "06":


        console.log("小月")
        //月 最后一天
        var month_end_date = Date.parse((this.data.date_month) + '-30') / 1000 - 28800
        this.setData({
          month_end_date: month_end_date
        })
        break;

      case "09":


        console.log("小月")
        //月 最后一天
        var month_end_date = Date.parse((this.data.date_month) + '-30') / 1000 - 28800
        this.setData({
          month_end_date: month_end_date
        })
        break;

      case "11":

        console.log("小月")
        //月 最后一天
        var month_end_date = Date.parse((this.data.date_month) + '-30') / 1000 - 28800
        this.setData({
          month_end_date: month_end_date
        })
        break;

      case "02":

        console.log("二月")

        if ((year % 4 == 0) && (year % 100 != 0 || year % 400 == 0)) {

          //月 最后一天
          var month_end_date = Date.parse((this.data.date_month) + '-29') / 1000 - 28800
          this.setData({
            month_end_date: month_end_date
          })
          break;

        } else {


          //月 最后一天
          var month_end_date = Date.parse((this.data.date_month) + '-28') / 1000 - 28800
          this.setData({
            month_end_date: month_end_date
          })
          break;

        }
    }
  },
  click_cur: function(e) {
    this.setData({
      day_start_date: app.globalData.start_date,
      day_end_date: app.globalData.start_date
    })
    // console.log(e.currentTarget.dataset)
    console.log(this.data.day_end_date)
    var that = this;
    var cur = e.currentTarget.dataset.cru_head;
    var head_id = e.currentTarget.dataset.head_id,
      head_type = e.currentTarget.dataset.head_type;
    var url = 'url("https://www.zhibohome.net/images/industry/ind_clicked.png")';
    //默认选择日排行
    this.setData({
      b1: url,
      b2: null,
      b3: null,

      t1: '#fff',
      t2: null,
      t3: null,
      ind_flag: "day",
    })

    if (that.data.current_Tab == cur) {
      return false;
    } else {
      that.setData({
        current_Tab: cur,
        head_switch: false,
        head_id: head_id,
        head_type: head_type,
        tuhao_all: [],
      })
    }
    // console.log('head_id+'+this.data.head_id)



    // 发起请求
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
    //调用 函数
    if (!(this.data.head_id)) {
      switch (this.data.module_) {
        case "user":
          this.tuhao_data(plat_token, this.data.day_start_date, this.data.day_end_date, "day");
          break;
        case "gift":
          this.gift_data(plat_token, this.data.day_start_date, this.data.day_end_date, "day");
          break;
        case "mes":
          this.mes_data(plat_token, this.data.day_start_date, this.data.day_end_date, "day");
          break;
      }
    } else {
      this.plat_data(plat_token, this.data.head_id, this.data.day_start_date, this.data.day_end_date, this.data.head_type, 'day')
    }
    //显示日期
    this.show_day(app.globalData.now_time)
  },
  click_all: function(e) {
    this.setData({
      day_start_date: app.globalData.start_date,
      day_end_date: app.globalData.start_date
    })
    // console.log(e)
    this.setData({
      current_Tab: null,
      head_switch: true,
      tuhao_all: [],
      head_id: '',
      ind_flag: "day",
    })

    // 发起请求
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
    //调用 函数
    if (!(this.data.head_id)) {
      switch (this.data.module_) {
        case "user":
          this.tuhao_data(plat_token, this.data.day_start_date, this.data.day_end_date, "day");
          break;
        case "gift":
          this.gift_data(plat_token, this.data.day_start_date, this.data.day_end_date, "day");
          break;
        case "mes":
          this.mes_data(plat_token, this.data.day_start_date, this.data.day_end_date, "day");
          break;
      }
    } else {
      this.plat_data(plat_token, this.data.head_id, this.data.day_start_date, this.data.day_end_date, this.data.head_type, 'day')
    }
    //显示日期
    this.show_day(app.globalData.now_time)
  },




  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    this.setData({
      day_start_date: app.globalData.start_date,
      day_end_date: app.globalData.start_date,
      week_date: app.globalData.week
    })
    var module_ = options.module;
    this.setData({
      module_: module_
    })
    if (module_ == "user") {
      this.setData({
        ind_module: 'tuhao/user',
        collect_type: '1',
      })
      wx.setNavigationBarTitle({
        title: options.title //页面标题为路由参数
      })
    }
    if (module_ == "gift") {
      this.setData({
        ind_module: 'gift/list',
        collect_type: '2',
      })
      wx.setNavigationBarTitle({
        title: options.title //页面标题为路由参数
      })
    }
    if (module_ == "mes") {
      this.setData({
        ind_module: 'bullet/list',
        collect_type: '3',
      })
      wx.setNavigationBarTitle({
        title: options.title //页面标题为路由参数
      })
    }

    //token
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';

    wx.request({
      method: 'POST',
      url: 'https://xcz.zhibohome.net/api/home/collect/head',
      data: {
        token: plat_token,
        collect_type: this.data.collect_type,
        type: 1
      },
      success: function(e) {
        //    console.log(e.data.data.head);
        var plat_head = (e.data.data.head);
        that.setData({
          plat_head: plat_head,

        })
        //    console.log(that.data.plat_head)
      }
    })

    console.log(options)

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    //显示时间
    var time_ = app.globalData.now_time;
    var day_ = this.show_day(time_)

    // 发起请求
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
    //调用 函数
    if (!(this.data.head_id)) {
      switch (this.data.module_) {
        case "user":
          this.tuhao_data(plat_token, this.data.day_start_date, this.data.day_start_date, "day");
          break;
        case "gift":
          this.gift_data(plat_token, this.data.day_start_date, this.data.day_start_date, "day");
          break;
        case "mes":
          this.mes_data(plat_token, this.data.day_start_date, this.data.day_start_date, "day");
          break;
      }
    } else {
      this.plat_data(plat_token, this.data.head_id, this.data.day_start_date, this.data.day_end_date, this.data.head_type, 'day')
    }



    //上一页返回
    let pages = getCurrentPages();
    let currPage = pages[pages.length - 1];

    // console.log('上一页面+'+currPage.data.head_id);
    // console.log('上一页面+' + currPage.data.plat_type);
    var send_head_id = currPage.data.head_id
    var send_head_type = currPage.data.head_type

    console.log(send_head_id + '+' + send_head_type)
    if (currPage.data.selAddress) {
      that.setData({ //将携带的参数赋值
        head_id: send_head_id,
        head_type: send_head_type,
        head_switch: currPage.data.head_switch,
        current_Tab: null,
        tuhao_all: []
      });
    }
    var url = 'url("https://www.zhibohome.net/images/industry/ind_clicked.png")';
    //默认选择日排行
    this.setData({
      b1: url,
      b2: null,
      b3: null,

      t1: '#fff',
      t2: null,
      t3: null,
    })

    // month_start_date=null;
    // month_end_date = null;



  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})